package com.terry.test3;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 最少面试官数
 *  n m
 *
 * @author 小八
 * @date 2023年02月13日9:52
 */
public class Title28 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            String[] split = scanner.nextLine().split(" ");
            //一个面试官最多面试人次
            Integer m  = Integer.parseInt(split[0]);
            //有多少场面试
            Integer n = Integer.parseInt(split[1]);
            int[][] arr = new int[n][2];
            for (int i = 0; i < n; i++) {
                String[] temp = scanner.nextLine().split(" ");
                arr[i][0] = Integer.parseInt(temp[0]);
                arr[i][1] = Integer.parseInt(temp[1]);
            }
            Arrays.sort(arr,(a,b)->{
                if(a[0] == b[0]){
                    return a[1] - b[1];
                }else{
                    return a[0] - b[0];
                }
            });
            int msgCount = 1;
            int useCount = 0;
            int[] msgArr  = new int[n];
            for (int i = 0; i < n; i++) {
                if(msgArr[i]==0){
                    msgArr[i] = msgCount;
                    useCount++ ;
                }
                for(int j=1;j<n;j++){
                    //可以并行
                    if(arr[j][0]>= arr[i][1] && msgArr[j]==0){
                        useCount++ ;
                        msgArr[j] = msgCount;
                        if(useCount == m){
                            msgCount++;
                            useCount = 0;
                        }
                    }
                }
                msgCount++;
            }
            System.out.println(Arrays.stream(msgArr).boxed().distinct().count());
        }
    }
}
//2 5
//1 2
//2 3
//3 4
//4 5
//5 6